package com.zhuzi.utils;

import org.jsoup.Connection;

import java.io.IOException;
import java.time.LocalDate;
import java.util.Collections;
import java.util.concurrent.ConcurrentSkipListMap;

/**
 * 巨潮工具类
 * 2023年01月28日17:28:30
 */
public class JcUtils {
    private static final String QUERY_URL = "http://www.cninfo.com.cn/new/hisAnnouncement/query";

    /**
     * 巨潮公告-搜索
     * <p></p>
     * <code>seDate:  2023-01-29~2023-01-29</code>
     *
     * @param searchKey 向下;修正
     */
    public static Connection.Response query(String searchKey, LocalDate start, LocalDate end) throws IOException {
        ConcurrentSkipListMap<String, String> map = new ConcurrentSkipListMap<>();
        map.putIfAbsent("pageNum", "1");
        map.putIfAbsent("pageSize", "30");
        map.putIfAbsent("column", "szse");
        map.putIfAbsent("tabName", "fulltext");
        map.putIfAbsent("plate", "");
        //"减持公司可转换"
        map.putIfAbsent("searchkey", searchKey);
        map.putIfAbsent("stock", "");
        // "2021-08-23~2022-02-23"
        map.putIfAbsent("seDate", String.format("%s~%s", start, end));
        map.putIfAbsent("sortName", "");
        map.putIfAbsent("sortType", "");
        map.putIfAbsent("isHLtitle", "false");
        map.putIfAbsent("secid", "");
        map.putIfAbsent("category", "");
        map.putIfAbsent("trade", "");
        return JsoupHttpUtils.post(QUERY_URL, Collections.EMPTY_MAP, map, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
    }
}
